package com.zzc.control;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.zzc.dao.BaseDaoImpl;
import com.zzc.dao.ProductDao;
import com.zzc.dao.StorageDao;
import com.zzc.pojo.Product;

@Controller
@RequestMapping("/product")
public class ProductControl extends BaseControl{
	@Autowired
	public ProductDao pd;
	@Autowired
	public StorageDao sd;
	@RequestMapping("/findbyallproduct")
	public String findByAllPro(){
		List<Product> list=pd.findByAllProduct();
		session.setAttribute("productlist", list);
		return "product_all";
	}
	@RequestMapping("/findbydealproduct")
	public String findByDealPro(){
		List<Product> list=pd.findByDealProduct();
		session.setAttribute("productlist_deal", list);
		return "product_deal";
	}
	@RequestMapping("/findbyproid")
	public String findByProId(@RequestParam("pid") Integer pid){
		Product product=pd.findProductById(pid);
		session.setAttribute("productgoout", product);
		return "goout_detail";
	}
	@RequestMapping("/movebyid")
	public String moveById(@RequestParam("pid") Integer pid){
		Product product=pd.findProductById(pid);
		session.setAttribute("productmove", product);
		return "move_detail";
	}
	@RequestMapping("/updateaddr")
	public String updateAddr(String newAddr){
		Product moveproduct=(Product)session.getAttribute("productmove");
		Integer pid =moveproduct.getPid();
		moveproduct.setPaddr(newAddr);
		try {
			pd.update(moveproduct);
			return "success";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "error";
		}
	}
}
